package com.xiaoman.international;



import com.xiaoman.international.annotation.EnableLanguageConvert;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
@Slf4j
public class InternationalAspect {
    @AfterReturning(value = "@annotation(com.xiaoman.international.annotation.EnableLanguageConvert)", returning = "result")
    public void doInternational(JoinPoint joinPoint, Object result) {
        try {
            MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
            Method method = methodSignature.getMethod();
            EnableLanguageConvert annotation = method.getAnnotation(EnableLanguageConvert.class);
            CommonInternationHandle.baseSetInternational(result, null, annotation.value());
        } catch (Exception e) {
            log.error("International Exception : " + e.getMessage());
        }
    }
}
